//
//  ExtensionUIView.m
//  LetvIphoneClient
//
//  Created by guangliang shen on 1/17/11.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "ExtensionUIView.h"
#import <QuartzCore/QuartzCore.h>

#ifdef LT_MERGE_FROM_IPAD_CLIENT
@implementation  UIView (SubView)
-(void)removeSubViews{
    for (UIView *v in [self subviews]) {
        [v removeFromSuperview];
    }
}
+(UIView *) getViewByClassName:(UIView *)parentView withClassName:(NSString *)className{
    for (UIView *v in [parentView subviews]) {
        
        if ([className isEqualToString:NSStringFromClass([v class])]) {
            return v;
        } else {
            UIView *tview = [self getViewByClassName:v withClassName:className];
            if (tview) {
                return tview;
            }
            continue;
        }
    }
    return nil;
}

- (void)hide:(BOOL)bHide
    animated:(BOOL)bAniamtion
    alphaMax:(CGFloat)alphaMax
    duration:(NSTimeInterval)duration{
    
    if (!bAniamtion) {
        self.hidden = bHide;
        self.alpha = alphaMax;
        return;
    }
    
    if (alphaMax < 0.f) {
        alphaMax = 0.f;
    }
    if (alphaMax > 1.f) {
        alphaMax = 1.f;
    }
    
    if (bHide) {
        self.alpha = alphaMax;
    }
    else{
        self.alpha = 0.f;
    }
    
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
    [UIView setAnimationDuration:duration];
    
    if (bHide) {
        self.alpha = 0.f;
        self.opaque = NO;
    }
    else{
        self.alpha = alphaMax;
        self.opaque = YES;
    }
    
    [UIView commitAnimations];
    
    return;
}

- (void)addBackGroudImage:(UIImage *)image
{
    UIImageView *bgImg = [[UIImageView alloc] initWithFrame:CGRectMake(0,
                                                                       0,
                                                                       CGRectGetWidth(self.frame),
                                                                       CGRectGetHeight(self.frame)
                                                                       )];
    bgImg.image = image;
    bgImg.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
    [self addSubview:bgImg];
    [self sendSubviewToBack:bgImg];
}

- (void)addBackGroudImageAtCenter:(UIImage *)image
{
    UIImageView *bgImg = [[UIImageView alloc] initWithFrame:CGRectMake((CGRectGetWidth(self.frame) - image.size.width) / 2.f,
                                                                       (CGRectGetHeight(self.frame) - image.size.height) / 2.f,
                                                                       image.size.width,
                                                                       image.size.height
                                                                       )];
    bgImg.image = image;
    bgImg.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin;
    [self addSubview:bgImg];
    [self sendSubviewToBack:bgImg];
}

+(void)addLineToControl:(UIView *)view forTopOrBottom:(BOOL)isTop WithColorRed:(CGFloat)red WithColorGreen:(CGFloat)green WithColorBlue:(CGFloat)blue withAlpha:(CGFloat)alpha{
    CGFloat original_y=isTop?0:view.frame.size.height-1;
    UIImageView *line=[[UIImageView alloc]initWithFrame:CGRectMake(0, original_y, view.frame.size.width, 1)];
    UIGraphicsBeginImageContext(line.frame.size);
    [line.image drawInRect:CGRectMake(0, 0, line.frame.size.width, line.frame.size.height)];
    CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);
    CGContextSetLineWidth(UIGraphicsGetCurrentContext(), line.frame.size.width);
    CGContextSetAllowsAntialiasing(UIGraphicsGetCurrentContext(), YES);
    CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), red/255, green/255, blue/255, alpha);
    CGContextBeginPath(UIGraphicsGetCurrentContext());
    CGContextMoveToPoint(UIGraphicsGetCurrentContext(), 0, 1);
    CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), line.frame.size.width, 1);
    CGContextStrokePath(UIGraphicsGetCurrentContext());
    line.image=UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    [view addSubview:line];
    
}

+(void)addVerticalLine:(UIView *)view forLeftOrRight:(BOOL)isLeft  WithColorRed:(CGFloat)red WithColorGreen:(CGFloat)green WithColorBlue:(CGFloat)blue withAlpha:(CGFloat)alpha{
    
    CGFloat original_x=isLeft?0:view.frame.size.width-1;
    UIImageView *line=[[UIImageView alloc]initWithFrame:CGRectMake(original_x, 0, 1, view.frame.size.height)];
    UIGraphicsBeginImageContext(line.frame.size);
    [line.image drawInRect:CGRectMake(0, 0, line.frame.size.width, line.frame.size.height)];
    CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);
    CGContextSetLineWidth(UIGraphicsGetCurrentContext(), line.frame.size.width);
    CGContextSetAllowsAntialiasing(UIGraphicsGetCurrentContext(), YES);
    CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), red/255, green/255, blue/255, alpha);
    CGContextBeginPath(UIGraphicsGetCurrentContext());
    CGContextMoveToPoint(UIGraphicsGetCurrentContext(), 0, 1);
    CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), 1, line.frame.size.height);
    CGContextStrokePath(UIGraphicsGetCurrentContext());
    line.image=UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    [view addSubview:line];
}

- (void)set7Frame:(CGRect)frame
{
    CGRect tmpRect = frame;
    if (LTAPI_IS_ALLOWED(7.0)) {
        tmpRect.origin.y += 20.f;
    }
    
    [self setFrame:tmpRect];
}

@end

@implementation  UIView (LTWobble)

- (CAAnimation *)wobbleRotationAnimation {
    CAKeyframeAnimation *anim = [CAKeyframeAnimation animationWithKeyPath:@"transform.rotation"];
    anim.values = @[[NSNumber numberWithFloat:-M_PI/100.f],
                    [NSNumber numberWithFloat:M_PI/100.f]];
    anim.duration = 0.1f;
    anim.autoreverses = YES;
    anim.repeatCount = HUGE_VALF;
    anim.additive = YES;
    return anim;
}

- (CAAnimation *)wobbleTranslationYAnimation {
    CAKeyframeAnimation *anim = [CAKeyframeAnimation animationWithKeyPath:@"transform.translation.y"];
    anim.values = @[@-0.5f,
                      @0.5f];
    anim.duration = 0.08f;
    anim.autoreverses = YES;
    anim.repeatCount = HUGE_VALF;
    anim.additive = YES;
    return anim;
}

- (void)stopWobble{
    
    [self.layer removeAnimationForKey:@"ltWobbleAnimationRotation"];
    [self.layer removeAnimationForKey:@"ltWobbleAnimationTranslationY"];
    
    return;
}

- (void)startWobble{
    CAAnimation *rotationAnimation = [self wobbleRotationAnimation];
    [self.layer addAnimation:rotationAnimation forKey:@"ltWobbleAnimationRotation"];
    
    CAAnimation *translationYAnimation = [self wobbleTranslationYAnimation];
    [self.layer addAnimation:translationYAnimation forKey:@"ltWobbleAnimationTranslationY"];
}

+ (UIImage *)roundedImageWithSize:(CGSize)size color:(UIColor *)color radius:(CGFloat)radius {
    CGRect rect = CGRectZero;
    rect.size = size;
    
    UIBezierPath* path = [UIBezierPath bezierPathWithRoundedRect:rect cornerRadius:radius];
    
    UIGraphicsBeginImageContext(path.bounds.size);
    
    if (color) {
        [color set];
        [path fill];
    }
    if (color) {
        [color set];
        [path stroke];
    }
    
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    
    return image;
}

@end

#else
@implementation  UIView (SubView)
-(void)removeSubViews{
	for (UIView *v in [self subviews]) {
		[v removeFromSuperview];
	}
}
+(UIView *) getViewByClassName:(UIView *)parentView withClassName:(NSString *)className{
	for (UIView *v in [parentView subviews]) {
		
		if ([className isEqualToString:NSStringFromClass([v class])]) {
			return v;
		} else {
			UIView *tview = [self getViewByClassName:v withClassName:className];
			if (tview) {
				return tview;
			}
			continue;
		}		
	}
	return nil;
}

- (void)hide:(BOOL)bHide
    animated:(BOOL)bAniamtion
    alphaMax:(CGFloat)alphaMax
    duration:(NSTimeInterval)duration{
	
	if (!bAniamtion) {
		self.hidden = bHide;
        self.alpha = alphaMax;
		return;
	}
	
	if (alphaMax < 0.f) {
		alphaMax = 0.f;
	}
	if (alphaMax > 1.f) {
		alphaMax = 1.f;
	}
	
	if (bHide) {
		self.alpha = alphaMax;
	}
	else{
		self.alpha = 0.f;
	}
	
	[UIView beginAnimations:nil context:nil];
	[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
	[UIView setAnimationDuration:duration];
	
	if (bHide) {
		self.alpha = 0.f;
		self.opaque = NO;
	}
	else{
		self.alpha = alphaMax;
		self.opaque = YES;
	}
	
	[UIView commitAnimations];	
	
	return;
}


+(void)addLineToControl:(UIView *)view forTopOrBottom:(BOOL)isTop WithColorRed:(CGFloat)red WithColorGreen:(CGFloat)green WithColorBlue:(CGFloat)blue withAlpha:(CGFloat)alpha{
    CGFloat original_y=isTop?0:view.frame.size.height-0.5;
    UIImageView *line=[[UIImageView alloc]initWithFrame:CGRectMake(0, original_y, view.frame.size.width, 0.5)];
    UIGraphicsBeginImageContext(line.frame.size);
    [line.image drawInRect:CGRectMake(0, 0, line.frame.size.width, line.frame.size.height)];
    CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);
    CGContextSetLineWidth(UIGraphicsGetCurrentContext(), line.frame.size.width);
    CGContextSetAllowsAntialiasing(UIGraphicsGetCurrentContext(), YES);
    CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), red/255.f, green/255.f, blue/255.f, alpha);
    CGContextBeginPath(UIGraphicsGetCurrentContext());
    CGContextMoveToPoint(UIGraphicsGetCurrentContext(), 0, 0.5);
    CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), line.frame.size.width, 0.5);
    CGContextStrokePath(UIGraphicsGetCurrentContext());
    line.image=UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    [view addSubview:line];
    
}

+(void)addLineToControl2:(UIView *)view forTopOrBottom:(BOOL)isTop WithColorRed:(CGFloat)red WithColorGreen:(CGFloat)green WithColorBlue:(CGFloat)blue withAlpha:(CGFloat)alpha{
    CGFloat original_y=isTop?0:view.frame.size.height-1;
    UIImageView *line=[[UIImageView alloc]initWithFrame:CGRectMake(0, original_y, view.frame.size.width, 0.5)];
    UIGraphicsBeginImageContext(line.frame.size);
    [line.image drawInRect:CGRectMake(0, 0, line.frame.size.width, line.frame.size.height)];
    CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);
    CGContextSetLineWidth(UIGraphicsGetCurrentContext(), line.frame.size.width);
    CGContextSetAllowsAntialiasing(UIGraphicsGetCurrentContext(), YES);
    CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), red/255.f, green/255.f, blue/255.f, alpha);
    CGContextBeginPath(UIGraphicsGetCurrentContext());
    CGContextMoveToPoint(UIGraphicsGetCurrentContext(), 0, 0.5);
    CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), line.frame.size.width, 0.5);
    CGContextStrokePath(UIGraphicsGetCurrentContext());
    line.image=UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    [view addSubview:line];
    
}

+(void)addLineToControl3:(UIView *)view forTopOrBottom:(BOOL)isTop  xSpace:(float)xSpace leftColor:(UIColor *)leftColor leftLength:(float)leftLength rightColor:(UIColor *)rightColor rightLength:(float)rightLength {
    
    // 去掉红蓝线
    return;
    
    CGFloat original_y=isTop?0:view.frame.size.height-1;
    UIImageView *line=[[UIImageView alloc]initWithFrame:CGRectMake(xSpace, original_y, leftLength, 1)];
    UIGraphicsBeginImageContext(line.frame.size);
    [line.image drawInRect:CGRectMake(0, 0, line.frame.size.width, line.frame.size.height)];
    CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapButt);
    CGContextSetLineWidth(UIGraphicsGetCurrentContext(), line.frame.size.width);
    CGContextSetAllowsAntialiasing(UIGraphicsGetCurrentContext(), YES);
    // CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), red/255.f, green/255.f, blue/255.f, alpha);
    CGContextSetStrokeColorWithColor(UIGraphicsGetCurrentContext(), leftColor.CGColor);
    CGContextBeginPath(UIGraphicsGetCurrentContext());
    CGContextMoveToPoint(UIGraphicsGetCurrentContext(), 0, 0);
    CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), line.frame.size.width, 0);
    CGContextStrokePath(UIGraphicsGetCurrentContext());
    line.image=UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    
    [view addSubview:line];
    
    line=[[UIImageView alloc]initWithFrame:CGRectMake(xSpace + leftLength, original_y, rightLength, 1)];
    UIGraphicsBeginImageContext(line.frame.size);
    [line.image drawInRect:CGRectMake(0, 0, line.frame.size.width, line.frame.size.height)];
    CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);
    CGContextSetLineWidth(UIGraphicsGetCurrentContext(), line.frame.size.width);
    CGContextSetAllowsAntialiasing(UIGraphicsGetCurrentContext(), YES);
    // CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), red/255.f, green/255.f, blue/255.f, alpha);
    CGContextSetStrokeColorWithColor(UIGraphicsGetCurrentContext(), rightColor.CGColor);
    CGContextBeginPath(UIGraphicsGetCurrentContext());
    CGContextMoveToPoint(UIGraphicsGetCurrentContext(), 0, 0);
    CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), line.frame.size.width, 0);
    CGContextStrokePath(UIGraphicsGetCurrentContext());
    line.image=UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    [view addSubview:line];
}


+(void)addVerticalLine:(UIView *)view forLeftOrRight:(BOOL)isLeft  WithColorRed:(CGFloat)red WithColorGreen:(CGFloat)green WithColorBlue:(CGFloat)blue withAlpha:(CGFloat)alpha{
    
    CGFloat original_x=isLeft?0:view.frame.size.width-0.5;
    UIImageView *line=[[UIImageView alloc]initWithFrame:CGRectMake(original_x, 0, 0.5, view.frame.size.height)];
    UIGraphicsBeginImageContext(line.frame.size);
    [line.image drawInRect:CGRectMake(0, 0, line.frame.size.width, line.frame.size.height)];
    CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);
    CGContextSetLineWidth(UIGraphicsGetCurrentContext(), line.frame.size.width);
    CGContextSetAllowsAntialiasing(UIGraphicsGetCurrentContext(), YES);
    CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), red/255.f, green/255.f, blue/255.f, alpha);
    CGContextBeginPath(UIGraphicsGetCurrentContext());
    CGContextMoveToPoint(UIGraphicsGetCurrentContext(), 0, 0.5);
    CGContextAddLineToPoint(UIGraphicsGetCurrentContext(),0.51, line.frame.size.height);
    CGContextStrokePath(UIGraphicsGetCurrentContext());
    line.image=UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    [view addSubview:line];
}


+(void)exChangeOut:(UIView *)changeOutView dur:(CFTimeInterval)dur{
    
    CAKeyframeAnimation * animation;
    
    animation = [CAKeyframeAnimation animationWithKeyPath:@"transform"];
    
    animation.duration = dur;
    
    animation.removedOnCompletion = NO;
    
    animation.fillMode = kCAFillModeForwards;
    
    NSMutableArray *values = [NSMutableArray array];
    
    [values addObject:[NSValue valueWithCATransform3D:CATransform3DMakeScale(1.0, 0.6, 1.0)]];
    
    [values addObject:[NSValue valueWithCATransform3D:CATransform3DMakeScale(1.0, 1.5, 1.0)]];
    
    [values addObject:[NSValue valueWithCATransform3D:CATransform3DMakeScale(1.0, 0.8, 0.9)]];
    
    [values addObject:[NSValue valueWithCATransform3D:CATransform3DMakeScale(1.0, 1.0, 1.0)]];
    
    
    animation.values = values;
    
    animation.timingFunction = [CAMediaTimingFunction functionWithName: @"easeInEaseOut"];
    
    [changeOutView.layer addAnimation:animation forKey:nil];
    
}

+(void)scaleView:(UIView *)view AnimationWithDuration:(NSTimeInterval)duration  isSelect:(BOOL)isSelect  completion:(void (^)(BOOL finished))completion{
    [UIView animateWithDuration:duration/4
     
                     animations:^{
                         
                         view.transform = CGAffineTransformMakeScale(0.6, 0.6);
                         
                     }completion:^(BOOL finish){
                         
                         [UIView animateWithDuration:duration/4
                          
                                          animations:^{
                                              
                                              view.transform = CGAffineTransformMakeScale(1.5, 1.5);
                                              
                                          }completion:^(BOOL finish){
                                              
                                              [UIView animateWithDuration:duration/4
                                               
                                                               animations:^{
                                                                   if (isSelect) {
                                                                       view.transform = CGAffineTransformMakeScale(0.6, 0.6);
                                                                   }else{
                                                                        view.transform = CGAffineTransformMakeScale(0.8, 0.8);
                                                                   }
                                                                  
                                                                   
                                                               }completion:^(BOOL finish){
                                                                   
                                                                   [UIView animateWithDuration:duration/4
                                                                    
                                                                                    animations:^{
                                                                                        
                                                                                        view.transform = CGAffineTransformMakeScale(1.0, 1.0);
                                                                                        
                                                                                    }completion:^(BOOL finish){
                                                                                        
                                                                                    
                                                                                        completion(finish);
                                                                                        
                                                                                    }];
                                                                   
                                                                   
                                                               }];
                                              
                                          }];
                         
                     }];

}




- (void)addBackGroudImage:(UIImage *)image
{
    UIImageView *bgImg = [[UIImageView alloc] initWithFrame:CGRectMake(0,
                                                                       0,
                                                                       CGRectGetWidth(self.frame),
                                                                       CGRectGetHeight(self.frame)
                                                                       )];
    bgImg.image = image;
    bgImg.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
    [self addSubview:bgImg];
    [self sendSubviewToBack:bgImg];
}

- (void)addBackGroudImageAtCenter:(UIImage *)image
{
    UIImageView *bgImg = [[UIImageView alloc] initWithFrame:CGRectMake((CGRectGetWidth(self.frame) - image.size.width) / 2.f,
                                                                       (CGRectGetHeight(self.frame) - image.size.height) / 2.f,
                                                                       image.size.width,
                                                                       image.size.height
                                                                       )];
    bgImg.image = image;
    bgImg.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin;
    [self addSubview:bgImg];
    [self sendSubviewToBack:bgImg];
}

+ (UIImage *)roundedImageWithSize:(CGSize)size color:(UIColor *)color radius:(CGFloat)radius {
    CGRect rect = CGRectZero;
    rect.size = size;
    
    UIBezierPath* path = [UIBezierPath bezierPathWithRoundedRect:rect cornerRadius:radius];
    
    UIGraphicsBeginImageContext(path.bounds.size);
    
    if (color) {
        [color set];
        [path fill];
    }
    if (color) {
        [color set];
        [path stroke];
    }
    
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    
    return image;
}

- (void)setCustomLayoutWithVisualFormat1:(NSString *)format1
                                 Format2:(NSString *)format2
                                 metrics:(NSDictionary *)metrics
                               superView:(UIView *)superView{
    if (!superView) {
        return;
    }
    if (!LTAPI_IS_ALLOWED(6.0)) {
        return;
    }
    [self setTranslatesAutoresizingMaskIntoConstraints:NO];
    //    [superView removeConstraints:self.constraints];
    NSMutableArray *removeArray = [[NSMutableArray alloc]init];
    for (NSLayoutConstraint *constraint in superView.constraints) {
        if (constraint.firstItem == self) {
            [removeArray addObject:constraint];
        }
    }
    [superView removeConstraints:removeArray];
    UIView *view=self;
    NSDictionary *views = NSDictionaryOfVariableBindings(view);
    NSArray *constranints1=[NSLayoutConstraint constraintsWithVisualFormat:format1
                                                                   options:0
                                                                   metrics:metrics
                                                                     views:views];
    [superView addConstraints:constranints1];
    
    NSArray *constranints2=[NSLayoutConstraint constraintsWithVisualFormat:format2
                                                                   options:0
                                                                   metrics:metrics
                                                                     views:views];
    [superView addConstraints:constranints2];
    
}
- (void)setCustomLayoutWithVisualFormat1:(NSString *)format1
                                 Format2:(NSString *)format2
                                 metrics:(NSDictionary *)metrics
                               superView:(UIView *)superView
                                   frame:(CGRect)frame{
    if (!superView) {
        return;
    }
    if (!LTAPI_IS_ALLOWED(6.0)) {
        self.frame = frame;
        return;
    }
    [self setTranslatesAutoresizingMaskIntoConstraints:NO];
    //    [superView removeConstraints:self.constraints];
    NSMutableArray *removeArray = [[NSMutableArray alloc]init];
    for (NSLayoutConstraint *constraint in superView.constraints) {
        if (constraint.firstItem == self) {
            [removeArray addObject:constraint];
        }
    }
    [superView removeConstraints:removeArray];
    UIView *view=self;
    NSDictionary *views = NSDictionaryOfVariableBindings(view);
    NSArray *constranints1=[NSLayoutConstraint constraintsWithVisualFormat:format1
                                                                   options:0
                                                                   metrics:metrics
                                                                     views:views];
    [superView addConstraints:constranints1];
    
    NSArray *constranints2=[NSLayoutConstraint constraintsWithVisualFormat:format2
                                                                   options:0
                                                                   metrics:metrics
                                                                     views:views];
    [superView addConstraints:constranints2];

    
    
}


- (CGRect)getNewFrameFromOldFrame:(CGRect)oldFrame
{
    CGRect newFrame;
    newFrame.origin.x = kRealWidth(oldFrame.origin.x);
    if (oldFrame.origin.x != 0) {
        newFrame.origin.y = newFrame.origin.x * (oldFrame.origin.y) / (oldFrame.origin.x);
    } else {
        newFrame.origin.y = 0.0;
    }
    
    
    newFrame.size.width = kRealWidth(oldFrame.size.width);
    if (oldFrame.size.width != 0) {
        newFrame.size.height = newFrame.size.width * oldFrame.size.height / oldFrame.size.width;
    } else {
        newFrame.size.height = 0.0;
    }
    
    newFrame = newFrame;
    return newFrame;
}

/*
- (NSDictionary *)getFrameFromView
{
    UIView *view=self;
    
    //++++++++++++++++++++++++
    CGFloat originX = view.frame.origin.x * SCRREN_PORTRAIT_WIDTH / 320;
    CGFloat originY = originX * view.frame.origin.y / view.frame.origin.y;
    CGFloat width = view.frame.size.width * SCRREN_PORTRAIT_WIDTH / 320;
    CGFloat height = width * view.frame.size.height / view.frame.size.width;
    NSDictionary *dic = @{@"originX":@(originX) , @"originY":@(originY) , @"width":@(width) , @"height":@(height)};
    return dic;
}
*/


@end
#endif

